package org.example.gateway.pojo.vo;

import org.example.gateway.exceptions.GatewayException;

import java.io.Serializable;

public class CommonResult<T> implements Serializable {
    private Integer code;

    private String message;

    private T data;

    public CommonResult() {
    }

    public static <T> CommonResult success(T data) {
        CommonResult<T> result = new CommonResult<>();
        result.setCode(200);
        result.setMessage("success");
        result.setData(data);
        return result;
    }
    public static <T> CommonResult<T> success() {
        CommonResult<T> result = new CommonResult();
        result.setCode(200);
        result.setMessage("success");
        return result;
    }


    public static <T> CommonResult<T> fail() {
        CommonResult<T> result = new CommonResult();
        result.setCode(500);
        result.setMessage("fail");
        return result;
    }


    public static <T> CommonResult<T> error(GatewayException exception) {
        CommonResult<T> result = new CommonResult();
        result.setCode(exception.getCode());
        result.setMessage(exception.getMessage());
        return result;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
